<template>
	<view>
		<view class="goods_list">
			<goods-list  @itemClick="goGoodsDetail" :goods="goods"></goods-list>
		</view>
		<view v-if="flag" class="isOver">--------已经到底了--------</view>
	</view>
</template>

<script>
	import goodsList from "../../components/goods_list/goods_list.vue"
	export default {
		components: {
			goodsList
		},
		onLoad() {
			this.getGoodsList()
		},
		onReachBottom() {
			console.log("触底")
			this.pageindex++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.pageindex = 1
			this.goods = []
			this.flag = false 
			setTimeout(()=>{
				this.getGoodsList(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
		},
		data() {
			return {
				pageindex: 1,
				goods: [],
				flag: false
			}
		},
		methods: {
			//获取商品列表数据
			async getGoodsList(callback) {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=' + this.pageindex
				})
				if (res.data.message.length < 10) {
					this.flag = true
				}
				this.goods = [...this.goods, ...res.data.message]
				console.log(this.goods, "商品")
				callback && callback()
			},
			goGoodsDetail(id) {
				console.log(id, "id")
				uni.navigateTo({
					url: '/pages/goods_detail/goods_detail?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods_list {
		background-color: #eee;
	}
	.isOver{
		width: 100%;
		height: 50px;
		line-height: 50px;
		text-align: center;
		// background-color: #FFFFFF;
	}
</style>
